#include <bits/stdc++.h>

using namespace std;

int c[31][31];
auto init = [] {
  for (int i = 0; i < 31; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
  return 0;
}();
class Solution {
 public:
  int waysToReachStair(int k) {
    long p = 1, mi = 0;
    while (p < k) {
      p *= 2;
      mi++;
    }
    int ans = k == 1 ? 1 : 0;
    while (p - (mi + 1) <= k) {
      int n = mi + 1, m = p - k;
      ans += c[n][m];
      p *= 2;
      mi++;
    }

    return ans;
  }
};
int main(int argc, char const *argv[]) {
  int res = Solution().waysToReachStair(1048555);
  cout << res << endl;
  return 0;
}